home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TEnvironment.cp
-
- Contains: Information about the software environment
-
- Written by: Arno Gourdol
-
- Copyright: © 1996 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #include "TEnvironment.h"
-
- #include <OSUtils.h>
- #include <Traps.h>
- #include <QDOffscreen.h>
- #include <LowMem.h>
- #include <Script.h>
-
- #include <assert.h>
-
-
-
- // --------------------------------------------------------------------
- // TEnvironment
- // --------------------------------------------------------------------
- // Constructor
-
- TEnvironment::TEnvironment() :
- fHasColorQuickdraw(triUnknown),
- fHasAppleEvent(triUnknown),
- fHasGestalt(triUnknown),
- fHasExtendedDITL(triUnknown),
- fSystemScriptIsRTL(triUnknown)
- {
- fUnimplementedTrapAddress = GetToolTrapAddress(_Unimplemented);
-
- if (!HasGestalt())
- {
- // FatalError();
- assert("Gestalt is required");
- }
-
- }
-
-
-
- // --------------------------------------------------------------------
- // HasGestalt
- // --------------------------------------------------------------------
- // Returns true if Gestalt is available
-
- Boolean TEnvironment::HasGestalt(void)
- {
- if (triUnknown == fHasGestalt)
- {
- if (GetOSTrapAddress(_Gestalt) == fUnimplementedTrapAddress)
- fHasGestalt = triFalse;
- else
- fHasGestalt = triTrue;
- }
-
- if (fHasGestalt == triTrue)
- return true;
- else
- return false;
- }
-
-
-
- // --------------------------------------------------------------------
- // HasColorQuickdraw
- // --------------------------------------------------------------------
- // Returns true if Color Quickdraw if available
-
- Boolean TEnvironment::HasColorQuickdraw(void)
- {
- if (fHasColorQuickdraw == triUnknown)
- {
- fHasColorQuickdraw = triFalse;
- if (HasGestaltAttribute(gestaltQuickdrawFeatures, gestaltHasColor))
- {
- fHasColorQuickdraw = triTrue;
- }
- }
-
- if (fHasColorQuickdraw == triTrue)
- return true;
- else
- return false;
- }
-
-
-
- // --------------------------------------------------------------------
- // HasAppleEvent
- // --------------------------------------------------------------------
- // Returns true if AppleEvents are available
-
- Boolean TEnvironment::HasAppleEvent(void)
- {
- if (fHasAppleEvent == triUnknown)
- {
- fHasAppleEvent = triFalse;
- if (HasGestaltAttribute(gestaltAppleEventsAttr, gestaltAppleEventsPresent))
- {
- fHasAppleEvent = triTrue;
- }
- }
-
- if (fHasAppleEvent == triTrue)
- return true;
- else
- return false;
- }
-
-
-
- // --------------------------------------------------------------------
- // HasExtendedDITL
- // --------------------------------------------------------------------
- // Returns true if Extended DITLs are available (AppendDITL...)
-
- Boolean TEnvironment::HasExtendedDITL(void)
- {
- if (fHasExtendedDITL == triUnknown)
- {
- fHasExtendedDITL = triFalse;
- if (HasGestaltAttribute(gestaltDITLExtAttr, gestaltDITLExtPresent))
- {
- fHasExtendedDITL = triTrue;
- }
- }
-
- if (fHasExtendedDITL == triTrue)
- return true;
- else
- return false;
- }
-
-
-
- // --------------------------------------------------------------------
- // GetMonitorRect
- // --------------------------------------------------------------------
- // Returns the rectangle of the monitor which contains most of r
-
- void TEnvironment::GetMonitorRect(const CRect& r, CRect& monitor)
- {
-
- if (!HasColorQuickdraw())
- {
- monitor = qd.screenBits.bounds;
- monitor.SetTop(monitor.Top() + LMGetMBarHeight());
- monitor.SetRight(monitor.Right() - 65); // Leaves room for icons
- }
- else
- {
- GDHandle bestDevice;
- long bestArea;
- long area;
- GDHandle device;
- Rect intersection;
- Rect deviceRect;
-
- device = GetDeviceList();
- bestArea = 0;
- bestDevice = NULL;
-
- while (device != NULL)
- {
- if (TestDeviceAttribute(device, screenDevice) && TestDeviceAttribute(device, screenActive))
- {
- deviceRect = (**device).gdRect;
- if (SectRect(r, &deviceRect, &intersection))
- {
- area = (intersection.right - intersection.left) * (intersection.bottom - intersection.top);
- if (area > bestArea)
- {
- bestDevice = device;
- bestArea = area;
- }
- }
- }
- device = GetNextDevice(device);
- }
-
- monitor = (**bestDevice).gdRect;
-
- if (bestDevice == GetMainDevice())
- {
- monitor.SetTop(monitor.Top() + LMGetMBarHeight());
- monitor.SetRight(monitor.Right() - 65); // Leaves room for icons
- }
- }
- }
-
-
-
- // --------------------------------------------------------------------
- // GetMainScreenRect
- // --------------------------------------------------------------------
- // Returns the bounds of the main monitor
-
- void TEnvironment::GetMainScreenRect(CRect& theMainScreenRect)
- {
- if (HasColorQuickdraw())
- {
- GDHandle theGDHand = LMGetMainDevice();
- theMainScreenRect = (**theGDHand).gdRect;
- }
- else
- theMainScreenRect = LMGetWMgrPort()->portRect;
-
- theMainScreenRect.SetTop(theMainScreenRect.Top() + LMGetMBarHeight());
- }
-
-
-
- // --------------------------------------------------------------------
- // IsSystemScriptRTL
- // --------------------------------------------------------------------
- // Returns true if the system script is right to left
-
- Boolean TEnvironment::IsSystemScriptRTL(void)
- {
- if (fSystemScriptIsRTL == triUnknown)
- {
- fSystemScriptIsRTL = triFalse;
- if (::GetScriptVariable(smSystemScript, smScriptRight) != 0)
- {
- fSystemScriptIsRTL = triTrue;
- }
- }
-
- if (fSystemScriptIsRTL == triTrue)
- return true;
- else
- return false;
- }
-